using System;
using System.Collections.Generic;
using System.Text;

using NSimpleDB.Service.Contract;
using Forum.Contracts;

namespace Forum.DataAccess.Retrievers
{
    class SequentialPostingRetriever : IPostingRetriever
    {
        #region IPostingRetriever Members

        public Posting[] Retrieve(IDataAccess da, ISimpleDBService db, Posting parent, string[] postingIds)
        {
            List<Posting> postings = new List<Posting>();

            foreach (string id in postingIds)
            {
                ISimpleDBAttribute[] attributes;
                attributes = db.GetAttributes(Mapping.Mapper.ForumsDomainName, id, "subject", "text", "createdAt", "createdBy");
                Posting p = Mapping.Mapper.MapAttributes2Posting(da, attributes, id, parent);
                postings.Add(p);
            }

            postings.Sort(delegate(Posting a, Posting b) { return a.CreatedAt.CompareTo(b.CreatedAt); });
            return postings.ToArray();
        }

        #endregion
    }
}
